import 'package:bloc/bloc.dart';
import 'package:website.core/core/application/blocs/app_navigator_bloc/bloc.dart';
import 'package:website.core/core/application/blocs/app_navigator_bloc/models/page_models/documentation_page_model.dart';
import 'package:website.core/core/application/blocs/app_navigator_bloc/models/page_models/faq_page_model.dart';
import 'package:website.core/core/application/blocs/url_launcher_bloc/bloc.dart';
import 'package:website.core/core/domain/config/config.dart';

part 'bloc_state.dart';

class AppFooterBloc extends Cubit<AppFooterBlocState> {
  AppFooterBloc({
    required UrlLauncherBloc urlLauncherBloc,
    required AppNavigatorBloc appNavigatorBloc,
  })  : _urlLauncherBloc = urlLauncherBloc,
        _appNavigatorBloc = appNavigatorBloc,
        super(_getInitialState());

  final UrlLauncherBloc _urlLauncherBloc;
  final AppNavigatorBloc _appNavigatorBloc;

  static AppFooterBlocState _getInitialState() {
    return const AppFooterBlocState();
  }

  void openTermsOfUse() {
    _urlLauncherBloc.launch(
      url: Config().termsOfUseUrl,
    );
  }

  void openPrivacyPolicy() {
    _urlLauncherBloc.launch(
      url: Config().privacyPolicyUrl,
    );
  }

  void openEmailApp() {
    final url = Uri.encodeFull('mailto:${Config().supportEmail}');

    _urlLauncherBloc.launch(
      url: url,
    );
  }

  void openTelegramChannel() {
    _urlLauncherBloc.launch(
      url: Config().telegramChannelWelcomeMessageUrl,
    );
  }

  void openFaqPage() {
    final pageModel = FaqPageModel();

    _appNavigatorBloc.pushPageReplacement(
      pageModel: pageModel,
    );
  }

  void openDocumentationPage() {
    final pageModel = DocumentationPageModel();

    _appNavigatorBloc.pushPageReplacement(
      pageModel: pageModel,
    );
  }
}
